package com.neusoft.neuiotms.dcom.repository.change.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.change.ChangeRegistration;
import com.neusoft.neuiotms.dcom.model.change.QChangeRegistration;
import com.neusoft.neuiotms.dcom.repository.change.CustomizedChangeRegistrationRepository;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedChangeRegistrationRepositoryImpl extends AbstractRepository
        implements CustomizedChangeRegistrationRepository {

    @Override
    protected Class<?> getModelClass() {
        return ChangeRegistration.class;
    }

    @Override
    public ChangeRegistration findByWorkNum(final String workOrderNum) {
        final QChangeRegistration qChangeRegistration = QChangeRegistration.changeRegistration;
        final JPAQuery<ChangeRegistration> query = this.query().selectFrom(qChangeRegistration);
        query.where(qChangeRegistration.workOrderNum.eq(workOrderNum))
                .orderBy(qChangeRegistration.createTime.desc()).limit(1);
        return query.fetchOne();
    }

}
